package logic

import (
	"context"
	"hema-fresh/hemarpc/models/mysql"

	"hema-fresh/hemarpc/hemarpc"
	"hema-fresh/hemarpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductDetailLogic {
	return &ProductDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *ProductDetailLogic) ProductDetail(in *hemarpc.ProductDetailRequest) (*hemarpc.ProductDetailResponse, error) {
	// todo: add your logic here and delete this line

	var hema mysql.HemaProduct
	if err := hema.ProductDetail(mysql.DB, in.HemaProductId); err != nil {
		return nil, err
	}

	return &hemarpc.ProductDetailResponse{
		ProductName:   hema.ProductName,
		ProductPrice:  float32(hema.ProductPrice),
		ProductStock:  int64(hema.ProductStock),
		HemaTypeId:    int64(hema.HemaTypeId),
		HemaProductId: int64(hema.ID),
	}, nil
}
